import React, { useState, useEffect } from 'react';
import { useParams, useNavigate } from 'react-router-dom'
import { PlusOutlined } from '@ant-design/icons';
import {
    message,
    Form,
    Input,
    Button,
    Select,
    InputNumber,
    Switch,
    Upload,
    Image,
} from 'antd';

import request, { baseUrl } from '@/utils/request'

const ManagerChange = () => {
    const navigate = useNavigate()

    const { id } = useParams();

    const [myform] = Form.useForm()

    const [datalist, setdatalist] = useState({})
    const getData = async () => {
        const { data } = await request.get('/manager/manager/' + id)
        setdatalist(data.data[0])

        myform.setFieldsValue(data.data[0])
    }


    const [booktype,setbooktype] = useState([])

    const submit = async ({ id, ...values }) => {

        const { data } = await request.put('/manager/change/' + id, values)
        if (data.code === 200) {
            message.success('修改成功')
            navigate('/manage/manager_list')
        }
    }

    useEffect(() => {
        getData()

        request.get('/booktype/list').then(({data})=>{
            setbooktype(data.data)
        })
    }, [])

    return (
        <div>
            <div className='userchange'>
                <Form
                    labelCol={{ span: 4 }}
                    wrapperCol={{ span: 18 }}
                    layout="horizontal"
                    initialValues={datalist}
                    onFinish={submit}
                    form={myform}
                >
                    <Form.Item wrapperCol={{offset: 8,span: 16,}}>
                        <h1 className='changeruserhead'>请修改管理者信息</h1>
                    </Form.Item>
                    <Form.Item name="manager—_id" hidden>
                        <Input />
                    </Form.Item>
                    <Form.Item label="管理者名称" name="manager">
                        <Input />
                    </Form.Item>
                    <Form.Item label="管理者密码" name='password'>
                        <Input />
                    </Form.Item>
                    <Form.Item wrapperCol={{ offset: 4 }}>
                        <Button type='primary' htmlType='submit'>修改</Button>
                    </Form.Item>
                    <Form.Item wrapperCol={{offset: 8,span: 16,}}>
                    <span>提示：请修改管理者用户名与登录密码信息</span>
                </Form.Item>
                </Form>
            </div>

        </div>
    )
}


export default ManagerChange;